<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        canvas{
            border:1px solid #000;
        }
    </style>
</head>
<body>
    <canvas id="myCanvas">  
    </canvas>
    <script>
        const canvas = document.getElementById('myCanvas');
        var ctx = canvas.getContext('2d');
        ctx.fillStyle = 'red';
        ctx.font = "50px Verdana";        
        let dis = 550;
        let i = 10;
        function animation(){
        requestAnimationFrame(function(){        
            if(dis >= 0){
                --dis;
                if(dis%50 == 0 ){
                    ctx.clearRect(0,0,300,150);
                    ctx.fillText(i--,100,100);
                }
                animation();//递归
            }                
        });
        }
        animation();
        // canvas.width = '50';
        // canvas.style.width = '50vw';
        // canvas.style.height = '50vh';
        // canvas.width = window.innerWidth;
        // canvas.height = window.innerHeight;   
        </script>
</body>
</html>